package com.ljl.module.system.dao;

import com.ljl.module.system.domain.Resource;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Repository
public class ResourceDaoImpl implements ResourceDao {

    protected static final ConcurrentHashMap<String, Resource> MAP = new ConcurrentHashMap<>();

    @Override
    public Resource save(Resource resource) {
        if (!StringUtils.hasText(resource.getUuid())) {
            return null;
        }
        return MAP.put(resource.getUuid(), resource);
    }

    @Override
    public Resource findByUuid(String uuid) {
        return MAP.get(uuid);
    }

    @Override
    public List<Resource> findAll() {
        return new ArrayList<>(MAP.values());
    }

    @Override
    public Resource remove(String uiid) {
        return MAP.remove(uiid);
    }

}
